package com.haixiaoke.flat.user.controller;

import java.util.List;

import com.haixiaoke.auth.AuthCheck;
import com.haixiaoke.saas.user.service.IUserConsumerService;
import com.haixiaoke.saas.common.annotation.Log;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.common.enums.BusinessType;
import com.haixiaoke.saas.system.BaseController;
import com.haixiaoke.saas.user.domain.UserConsumer;
import com.haixiaoke.token.FrontTokenComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * C端用户Controller
 *
 * @author panda
 * @date 2024-04-11
 */
@RestController
@RequestMapping("/front/user/consumer")
public class FlatUserConsumerController extends BaseController {
    @Autowired
    private IUserConsumerService userConsumerService;
    @Autowired
    private FrontTokenComponent frontTokenComponent;

    /**
     * 获取C端用户详细信息
     */
    @AuthCheck
    @GetMapping
    public AjaxResult getInfo() {
        return success(userConsumerService.selectUserConsumerByUserId(frontTokenComponent.getUserIdNotNull()));
    }

    /**
     * 修改C端用户
     */
    @AuthCheck
    @Log(title = "C端用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserConsumer userConsumer) {
        userConsumer.setUserId(frontTokenComponent.getUserIdNotNull());
        return toAjax(userConsumerService.updateUserConsumer(userConsumer));
    }
}
